package com.ruoyi.interview.service.impl;

import com.ruoyi.interview.annotation.TLog;

import com.ruoyi.interview.domain.Account;
import com.ruoyi.interview.mapper.AccountMapper;
import com.ruoyi.interview.service.IAccountService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.math.BigDecimal;

@Service
public class AccountServiceImpl implements IAccountService {

    @Resource
    private AccountMapper accountMapper;

    @Override
    @TLog(request = "POST")
    @Transactional(rollbackFor = Exception.class)
    public Boolean transferAccounts() throws FileNotFoundException {
        Integer a1 = 0;
        Integer a2 = 0;
        Account qiqi = accountMapper.selectAccountById(1L);
        Account wukong = accountMapper.selectAccountById(2L);
        BigDecimal qiqiAccBalance = qiqi.getAccBalance();
        BigDecimal wukongAccBalance = wukong.getAccBalance();
        qiqi.setAccBalance(BigDecimal.valueOf(qiqiAccBalance.doubleValue() - 500));
        wukong.setAccBalance(BigDecimal.valueOf(wukongAccBalance.doubleValue() + 500));
        a1 = accountMapper.updateAccountById(qiqi);
        new FileInputStream("ddd");
        a2 = accountMapper.updateAccountById(wukong);

        return 2 ==  (a1 + a2);
    }
}
